#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QColor>
#include <QPalette>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->sliderR, &QSlider::valueChanged, this, &MainWindow::on_slider_valueChanged);
    connect(ui->sliderG, &QSlider::valueChanged, this, &MainWindow::on_slider_valueChanged);
    connect(ui->sliderB, &QSlider::valueChanged, this, &MainWindow::on_slider_valueChanged);
    connect(ui->sliderA, &QSlider::valueChanged, this, &MainWindow::on_slider_valueChanged);
    emit ui->sliderR->valueChanged(1);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_slider_valueChanged(){
    QColor color;
    int R = ui->sliderR->value();
    int G = ui->sliderG->value();
    int B = ui->sliderB->value();
    int A = ui->sliderA->value();
    color.setRgb(R, G, B, A);
    QPalette palette = ui->textEdit->palette();
    palette.setColor(QPalette::Base, color);
    ui->textEdit->setPalette(palette);
}


void MainWindow::on_dial_valueChanged(int value)
{
    ui->lcdNumber->display(value);
}

void MainWindow::on_rBtnDec_clicked()
{
    ui->lcdNumber->setDigitCount(3);
    ui->lcdNumber->setDecMode();
}

void MainWindow::on_rBtnBin_clicked()
{
    ui->lcdNumber->setDigitCount(8);
    ui->lcdNumber->setBinMode();
}

void MainWindow::on_rBtnOct_clicked()
{
    ui->lcdNumber->setDigitCount(4);
    ui->lcdNumber->setOctMode();
}

void MainWindow::on_rBtnHex_clicked()
{
    ui->lcdNumber->setDigitCount(3);
    ui->lcdNumber->setHexMode();
}
